package com.hxy.subject.domain.handler.subject;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author haoxuyang
 * @Date 2024/9/8 20:13
 */
@Component
public class SubjectTypeFactory implements InitializingBean {

    @Resource
    private List<SubjectInfoTypeHandler> subjectInfoTypeHandlerList;

    private Map<String,SubjectInfoTypeHandler> handlerHashMap=new HashMap<>();

    public SubjectInfoTypeHandler getHandler(Integer subjectType){
        return handlerHashMap.get(subjectType);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        for (SubjectInfoTypeHandler subjectInfoTypeHandler : subjectInfoTypeHandlerList) {
            handlerHashMap.put(subjectInfoTypeHandler.getHandlerType(),subjectInfoTypeHandler);
        }
    }
}
